데이터 클래스

코드 악취 중 하나. 필드랑 accessor만 있는 클래스. 데이터만 있는 클래스가 있다는 건 어딘가에 자기 자리를 못찾은 코드들이 있을 가능성이 있다는 뜻.

예외

But there are exceptions, and one of the best exceptions is a record that’s being used as a result record from a distinct function invocation. A good example of this is the intermediate data structure after you’ve applied Split phase. A key characteristic of such a result record is that it’s immutable (at least in practice). Immutable fields don’t need to be encapsulated and information derived from immutable data can be represented as fields rather than getting methods. —Chapter 3, Refactoring: Improving the design of existing code

관련 리팩토링

  • Encapsulate record
  • Remove setting method
  • Move function
  • Extract function

2024 © ak